<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<html>
<head>
    <meta charset="UTF-8">
    <title>入住管理</title>
    <link rel="stylesheet" type="text/css" href="css/manhuaDate.1.0.css"/>
    <!--<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>-->
    <link rel="stylesheet" type="text/css" href="css/hotel.css"/>
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/manhuaDate.1.0.js"></script>
    <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <script type="text/javascript">
        $(function () {
            $("input.mh_date").manhuaDate({
                Event: "click",//可选
                Left: 0,//弹出时间停靠的左边位置
                Top: -332,//弹出时间停靠的顶部边位置
                fuhao: "-",//日期连接符默认为-
                isTime: false,//是否开启时间值默认为false
                beginY: 1949,//年份的开始默认为1949
                endY: 2100//年份的结束默认为2049
            });
        });
    </script>
</head>
<body class="check-body">
<input type="hidden" id="CuserName" th:value="${session.UserName}"/>
<input type="hidden" id="UserStatusid" th:value="${session.UserStatusid}"/>
<input type="hidden" id="UserType" th:value="${session.UserType}"/>
<script type="text/javascript">
    var uname = $('#CuserName').val();
    if(uname == ''){
        window.location.href = "toLogin.do";
    }
    var ustatusid = $('#UserStatusid').val();
    if(ustatusid == 1){
        window.location.href = "toDecode.do";
    }
    var UserType = $('#UserType').val();
    if(UserType === '经理'){
        window.location.href = "toStatement.do";
    }
</script>
<div class="check">
    <div class="check-button">
        <ul>
            <li style="margin-left: 420px"><a href="javascript:;" class="register-ok">确定登记</a></li>
            <li><a href="javascript:;" class="register-cancel">取消登记</a></li>
            <!--<li><a href="javascript:;" class="select-reserve">入住查询</a></li>-->
            <!--<li><a href="javascript:;" class="select-empty">空房查询</a></li>-->
        </ul>
    </div>
</div>
<div class="check-detail">
    <table>
        <thead>
            <tr>
                <td width="60px">编号</td>
                <td width="100px">姓名</td>
                <td width="100px">房间类型</td>
                <td width="100px">房间号</td>
                <td width="100px">房间状态</td>
                <td width="100px">入住时间</td>
                <td width="100px">退房时间</td>
                <td width="200px">备注</td>
            </tr>
        </thead>
        <tbody id="checkTbody">

        </tbody>
    </table>
    <div class="check-center">
        <ul class="pagination" id="page">
            按钮
        </ul>
        共<span id="totalPage"></span>页
    </div>
</div>
<div class="ok-window">
    <div class="close-window">
        确定登记<a href="#" class="closebutton">X</a>
    </div>
    <div class="window-content">
        <form method="post" action="addCheck.do">
            <div class="check-text">
                <ul>
                    <li>房间类型:</li>
                    <li>房间号:</li>
                    <li><label for="userName">姓名:</label></li>
                    <li><label for="Money">押金:</label></li>
                    <li><label for="Phone">电话号码:</label></li>
                    <li><label for="Identity">身份证:</label></li>
                    <li><label for="inRoom">入住时间:</label></li>
                    <li><label for="outRoom">退房时间:</label></li>
                    <li class="last"><label for="Remark">备注:</label></li>
                </ul>
            </div>
            <div class="check-input">
                <ul>
                    <li>
                        <select id="roomtype" name="roomType">
                            <option value="单人间">单人间</option>
                            <option value="标准间">标准间</option>
                            <option value="双人间">双人间</option>
                            <option value="豪华套房">豪华套房</option>
                            <option value="总统套房">总统套房</option>
                        </select>
                    </li>
                    <li>
                        <select id="roomid" name="roomId"></select>
                    </li>
                    <li><input type="text" id="userName" name="clientName"/></li>
                    <li><input type="text" id="Money" name="clientMoney"/></li>
                    <li><input type="text" id="Phone" name="clientPhone"/></li>
                    <li><input type="text" id="Identity" name="clientIdentity"/></li>
                    <li><input class="mh_date" type="text" name="roomIn" readonly="true" id="inRoom"/></li>
                    <li><input class="mh_date" type="text" name="roomOut" readonly="true" id="outRoom"/></li>
                    <li class="last"><textarea id="Remark" name="roomRemark"></textarea></li>
                </ul>
            </div>
            <div class="btncheck">
                <button class="btn-check">确定</button>
                <button class="check-cancel" type="button">取消</button>
            </div>
        </form>
    </div>
</div>
<div class="cancel-window">
    <div class="close-window">
        取消登记<a href="#" class="closebutton">X</a>
    </div>
    <div class="window-content">
        <form method="post" action="cancelCheck.do">
            <div class="check-text">
                <ul>
                    <li>房间类型:</li>
                    <li>房间号:</li>
                    <li><label for="userName2">姓名:</label></li>
                    <!--<li>押金:</li>
                    <li>电话号码:</li>-->
                    <li><label for="Identity2">身份证:</label></li>
                    <!--<li>入住时间:</li>
                    <li>退房时间:</li>
                    <li class="last">备注:</li>-->
                </ul>
            </div>
            <div class="check-input">
                <ul>
                    <li>
                        <select id="roomtype2" name="roomType">
                            <option value="单人间">单人间</option>
                            <option value="标准间">标准间</option>
                            <option value="双人间">双人间</option>
                            <option value="豪华套房">豪华套房</option>
                            <option value="总统套房">总统套房</option>
                        </select>
                    </li>
                    <li>
                        <select id="roomid2" name="roomId"></select>
                    </li>
                    <li><input type="text" name="clientName" id="userName2"/></li>
                    <!--<li><input type="text"/></li>
                    <li><input type="text"/></li>-->
                    <li><input type="text" name="clientIdentity" id="Identity2"/></li>
                    <!--<li><input type="text"/></li>
                    <li><input type="text"/></li>
                    <li class="last"><textarea></textarea></li>-->
                </ul>
            </div>
            <div class="btncheck">
                <button class="btn-check">确定</button>
                <button class="check-cancel" type="button">取消</button>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $(".ok-window").hide();
        $(".cancel-window").hide();
    });
    $(".register-ok").click(function () {
        $(".ok-window").show();
    });
    $(".register-cancel").click(function () {
        $(".cancel-window").show();
    });
    $(".closebutton").click(function () {
        $(".ok-window").hide();
        $(".cancel-window").hide();
    });
    $(".check-cancel").click(function () {
        $(".ok-window").hide();
        $(".cancel-window").hide();
    });
    var roomtype;
    roomtype = $("#roomtype").val();
    checkAdd();
    function checkAdd() {
        $("#roomid").empty();
        $("#roomtype").change(function (){
            $("#roomid").empty();
            roomtype = $("#roomtype").val();
            $.post(
                "selectAddType.do",
                {"roomtype":roomtype},
                function (data){
                    if (data.status == 0) {
                        var list = data.result;
                        for(var i=0;i<list.length;i++){
                            var id = list[i].hotelId;
                            $('#roomid').append('<option value = ' + id + '>' + id + '</option>');
                        }
                    } else if (data.status == 1) {
                        layer.msg(data.message);
                    }
                }
            );
        });
        $.post(
            "selectAddType.do",
            {"roomtype":roomtype},
            function (data){
                if (data.status == 0) {
                    var list = data.result;
                    for(var i=0;i<list.length;i++){
                        var id = list[i].hotelId;
                        $('#roomid').append('<option value = ' + id + '>' + id + '</option>');
                    }
                } else if (data.status == 1) {
                    layer.msg(data.message);
                }
            }
        );
    }
    var roomtype2;
    roomtype2 = $('#roomtype2').val();
    reserveDelete();
    function reserveDelete(){
        $("#roomid2").empty();
        $("#roomtype2").change(function (){
            $("#roomid2").empty();
            roomtype2 = $("#roomtype2").val();
            $.post(
                "selectDeleteType.do",
                {"roomtype2":roomtype2},
                function (data){
                    if (data.status == 0) {
                        var list = data.result;
                        for(var i=0;i<list.length;i++){
                            var id = list[i].hotelId;
                            $('#roomid2').append('<option value = ' + id + '>' + id + '</option>');
                        }
                    } else if (data.status == 1) {
                        layer.msg(data.message);
                    }
                }
            );
        });
        $.post(
            "selectDeleteType.do",
            {"roomtype2":roomtype2},
            function (data){
                if (data.status == 0) {
                    var list = data.result;
                    for(var i=0;i<list.length;i++){
                        var id = list[i].hotelId;
                        $('#roomid2').append('<option value = ' + id + '>' + id + '</option>');
                    }
                } else if (data.status == 1) {
                    layer.msg(data.message);
                }
            }
        );
    }
    findByPage(1);
    function findByPage(page) {
        $('#checkTbody').empty();
        var currentPage = page;
        $.post(
            "checkList.do",
            {'currentPage': currentPage},
            function (data){
                if (data.status == 0){
                    var pageBean = data.result;
                    var totalPage = pageBean.totalPage;
                    var RoomList = pageBean.lists;
                    var no = pageBean.pageSize * (currentPage - 1);
                    for (var i = 0;i<RoomList.length;i++){
                        $('#checkTbody').append('<tr>' +
                            '<input type="hidden" value="'+RoomList[i].roomRemark+'"/>'+
                            '<td width="60px">'+(no+i+1)+'</td>'+
                            '<td width="100px">'+RoomList[i].roomName+'</td>'+
                            '<td width="100px">'+RoomList[i].roomType+'</td>'+
                            '<td width="100px">'+RoomList[i].roomId+'</td>'+
                            '<td width="100px">'+RoomList[i].roomState+'</td>'+
                            '<td width="100px">'+RoomList[i].roomIn+'</td>'+
                            '<td width="100px">'+RoomList[i].roomOut+'</td>'+
                            '<td width="200px">'+'<a href="javascript:;" onclick="roomdetail(this)">查看详情</a>'+'</td>'+
                            '</tr>');
                    }
                    $('#page').empty();
                    var begin = 1;
                    var end = 1;
                    if (totalPage <= 5) {
                        begin = 1;
                        end = totalPage;
                    } else {
                        begin = currentPage - 2;
                        end = currentPage + 2;
                        if (begin <= 1) {
                            begin = 1;
                            end = 5;
                        }
                        if (end >= totalPage) {
                            begin = totalPage - 4;
                            end = totalPage;
                        }
                    }
                    //添加上一页的按钮
                    $('#page').append('<li id="left" class="" style="display: inline-block;border: 1px solid blue;width: 20px;height: 20px"><span onclick="findByPage(' + (currentPage - 1) + ')" >&laquo;</span></li>');
                    //添加中间的页数
                    for (var i = begin; i <= end; i++) {
                        $('#page').append('<li class="" style="display: inline-block;border: 1px solid blue;width: 20px;height: 20px"><a onclick="findByPage(' + i + ')">' + i + '</a></li>');
                    }
                    //添加下一页的按钮
                    $('#page').append('<li id="right" class="" style="display: inline-block;border: 1px solid blue;width: 20px;height: 20px"><span onclick="findByPage(' + (currentPage + 1) + ')" >&raquo;</span></li>');
                    if (currentPage == 1) {
                        //添加禁用样式
                        $('#left').addClass('disabled');
                        //清除点击事件
                        $('#left>span').removeAttr('onclick');
                    }
                    if (currentPage == totalPage) {
                        //添加禁用样式
                        $('#right').addClass('disabled');
                        //清除点击事件
                        $('#right>span').removeAttr('onclick');
                    }
                    //添加当前页的激活样式
                    $('#page>li').eq(currentPage - begin + 1).addClass('selectPage');
                    //显示总页数
                    $('#totalPage').html(totalPage);
                }else{
                    layer.msg(data.message);
                }
            }
        );
    }
    function roomdetail(btn) {
        var $tds = $(btn).parent().siblings();
        var roomremark = $($tds[0]).val();
        layer.alert(roomremark);
    }
</script>
</body>
</html>
